package com.xfly.app.ui;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.view.TitleBarView;

import java.util.HashMap;
import java.util.Map;

public class FkActivity extends BaseMvpActivity {

    TitleBarView title_bar;

    EditText phone,desc;
    Button enter;
    TextView num;

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_feedback);
    }

    @Override
    public void initViews() {
        title_bar = findViewById(R.id.title_bar);
        desc = findViewById(R.id.desc);
        phone = findViewById(R.id.phone);
        num = findViewById(R.id.num);
        enter = findViewById(R.id.enter);


        title_bar.setText("意见反馈");
    }

    @Override
    public void initEvents() {

        desc.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                num.setText(desc.length()+"/50");
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        phone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                enter.setBackgroundResource(R.drawable.btn_red2);
                enter.setEnabled(true);
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Map<String,String> map = new HashMap<>();
                map.put("content",desc.getText().toString());
                map.put("phone",phone.getText().toString());
                apiDataRepository.fk(map, new ApiNetResponse<Object>() {
                    @Override
                    public void onSuccess(Object data) {
                        showMsg("提交成功");
                        finish();
                    }
                });
            }
        });

        title_bar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
    }
}
